/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Main.java
 *
 * Created on Oct 8, 2010, 9:55:47 AM
 */

package cat200;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.Timer;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
 *
 * @author alex
 */
public class Main extends javax.swing.JFrame {

   private String url = "jdbc:derby://localhost:1527/sample";
    private String userID = "app";
    private String userPW = "app";
    private Connection con;
    private Statement stmt;
    private ResultSet rset;
    public static int EMP_ID=0;


    //int col1;
    String col2,col3;

    /** Creates new form Main */
    public Main() {
    	super("Janice Bakery Shop - Home Page");
        initComponents();
        setLocationRelativeTo(null);
        
        update();
        setTimer();
    }

    public Main(int code) {
    	super("Janice Bakery Shop - Home Page");
        initComponents();
        
        EMP_ID=code;
        update();
        setTimer();
        
        setLocationRelativeTo(null);
        connectDatabase();

        try
        {
            //connectDatabase();

            rset= getResultSet("SELECT EMP_ID,EMP_NAME,EMP_POSITION FROM APP.EMPLOYEE WHERE EMP_ID = "+code);
            System.out.println(rset);

            while(rset.next())
            {
                col1 = rset.getInt(1);
                col2 = rset.getString(2);
                col3 = rset.getString(3);
                jLabel7.setText(col1+"");
                jLabel8.setText(col2);
                jLabel9.setText(col3);

                if(col3.equals("EMPLOYEE"))
                    jButton11.setEnabled(false);
            }
            //con.close();
        }
        catch(Exception e)
        {
            System.out.println("ERROR : " + e.getMessage());
        }
    }

    private void connectDatabase()
    {
        try
        {
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            con=DriverManager.getConnection(url, userID, userPW);
        }


        catch (ClassNotFoundException ex)
        {
            Logger.getLogger(CAKE1.class.getName()).log(Level.SEVERE, null, ex);
        }        catch (SQLException ex)
        {
            Logger.getLogger(CAKE1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private ResultSet getResultSet(String doubt)
    {
        //connectDatabase();
        ResultSet outcome = null;
        try
        {
            stmt = con.createStatement();
            outcome = stmt.executeQuery(doubt);
        }
        catch (SQLException ex)
        {
            Logger.getLogger(CAKE1.class.getName()).log(Level.SEVERE, null, ex);
        }
        return outcome;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jButton9 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel2 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        jButton9.setText("jButton7");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setMinimumSize(new java.awt.Dimension(400, 300));
        jPanel1.setPreferredSize(new java.awt.Dimension(400, 300));
        jPanel1.setLayout(null);

        jLabel1.setFont(new java.awt.Font("Times New Roman", 3, 36));
        jLabel1.setForeground(new java.awt.Color(238, 26, 211));
        jLabel1.setText("JANICE BAKERY SHOP");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(170, 50, 460, 42);

        jButton1.setFont(new java.awt.Font("Times New Roman", 1, 10));
        jButton1.setText("LOGOUT");
        jButton1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1);
        jButton1.setBounds(620, 10, 64, 26);
        jPanel1.add(jSeparator1);
        jSeparator1.setBounds(40, 130, 600, 10);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "CAKE MENU", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 3, 18), new java.awt.Color(44, 42, 225))); // NOI18N
        jPanel2.setLayout(null);

        jButton2.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jButton2.setText("ICE CREAM CAKE");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton2);
        jButton2.setBounds(50, 270, 190, 40);

        jButton3.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jButton3.setText("CUP CAKE");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton3);
        jButton3.setBounds(50, 30, 190, 40);

        jButton4.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jButton4.setText("FRUIT CAKE");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton4);
        jButton4.setBounds(50, 90, 190, 40);

        jButton5.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jButton5.setText("CHEESE CAKE");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton5);
        jButton5.setBounds(50, 150, 190, 40);

        jButton6.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jButton6.setText("CHOCOLATE CAKE");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton6);
        jButton6.setBounds(50, 210, 190, 40);

        jPanel1.add(jPanel2);
        jPanel2.setBounds(20, 140, 300, 340);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "OPTION", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 3, 18), new java.awt.Color(44, 42, 225))); // NOI18N
        jPanel3.setLayout(null);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Employee", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Serif Condensed", 1, 14))); // NOI18N
        jPanel4.setLayout(null);

        jLabel5.setText("Name : ");
        jPanel4.add(jLabel5);
        jLabel5.setBounds(30, 50, 170, 20);

        jLabel4.setText("ID : ");
        jPanel4.add(jLabel4);
        jLabel4.setBounds(30, 20, 170, 20);

        jLabel6.setText("Position : ");
        jPanel4.add(jLabel6);
        jLabel6.setBounds(30, 80, 170, 20);

        jLabel9.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jPanel4.add(jLabel9);
        jLabel9.setBounds(110, 80, 160, 20);

        jLabel8.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jPanel4.add(jLabel8);
        jLabel8.setBounds(110, 50, 160, 20);

        jLabel7.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jPanel4.add(jLabel7);
        jLabel7.setBounds(110, 20, 160, 20);

        jPanel3.add(jPanel4);
        jPanel4.setBounds(10, 20, 290, 110);

        jButton7.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jButton7.setText("PROFILE");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton7);
        jButton7.setBounds(70, 140, 170, 30);

        jButton8.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jButton8.setText("SPECIAL ORDER");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton8);
        jButton8.setBounds(70, 180, 170, 30);

        jButton10.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jButton10.setText("ORDER LIST");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton10);
        jButton10.setBounds(70, 220, 170, 30);

        jButton11.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jButton11.setText("SETTING");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton11);
        jButton11.setBounds(70, 300, 170, 30);

        jButton12.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jButton12.setText("MEMBERSHIP");
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton12);
        jButton12.setBounds(70, 260, 170, 30);

        jPanel1.add(jPanel3);
        jPanel3.setBounds(350, 140, 310, 340);

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/JBS2.png"))); // NOI18N
        jPanel1.add(jLabel2);
        jLabel2.setBounds(40, 30, 120, 90);

        jLabel3.setText("date");
        jPanel1.add(jLabel3);
        jLabel3.setBounds(440, 10, 170, 30);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 700, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 500, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        this.setVisible(false);
        new Setting(col1).setVisible(true);
    }                                         

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        this.setVisible(false);
        new Secure().setVisible(true);
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        this.setVisible(false);
        new CAKE1("CUP CAKE").setVisible(true);
    }                                        

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        this.setVisible(false);
        new CAKE1("FRUIT CAKE").setVisible(true);
    }                                        

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        this.setVisible(false);
        new CAKE1("CHEESE CAKE").setVisible(true);
    }                                        

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        this.setVisible(false);
        new CAKE1("CHOCOLATE CAKE").setVisible(true);
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        this.setVisible(false);
        new CAKE1("ICE CREAM CAKE").setVisible(true);
    }                                        

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        this.setVisible(false);
        new profile(col1).setVisible(true);
    }                                        

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        this.setVisible(false);
        new specialOrder(col1, time).setVisible(true);
    }                                        

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        this.setVisible(false);
        new collectOrder().setVisible(true);
    }                                         

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        this.setVisible(false);
        new membership(col1).setVisible(true);
    }                
    
    public void setTimer() {
        int messageTimeout = 1000;
        timer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                update();
            }

        });
        timer.restart();
    }

    public void update() {
        Date currentTime = new Date();

        time++;
        SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy  hh:mm:ss");
        String dateString = formatter.format(currentTime);

        jLabel3.setText(dateString);
        //JOptionPane.showMessageDialog(null, "test3");
    }
    public int time = 0;
    public Timer timer;

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Main().setVisible(true);
            }
        });
    }
    
    public static int col1;
   // public static String col2;
   // public static String col3;

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration

}
